﻿//-----------------------------------------------------------------------
// <copyright file="Facet.cs" company="Forebrain Technology, LLC">
//
// Copyright (c) Forebrain Technology, LLC. All rights reserved.
// 
// This source code is released under the Microsoft Public License (Ms-PL).
//
// </copyright>
//-----------------------------------------------------------------------
namespace PivotCollectionTools.Xml
{
    using System;
    using System.Collections.ObjectModel;
    using System.Xml.Serialization;

    /// <summary>
    /// A container for a value (String, LongString, Number, DateTime, or Link) of 
    /// a property (FacetCategory) on an item. May be used to filter, sort, or 
    /// display detailed information about an item.
    /// </summary>
    [SerializableAttribute()]
    [XmlType(Namespace = "http://schemas.microsoft.com/collection/metadata/2009")]
    public class Facet : XmlNodeBase
    {
        /// <summary>
        /// Used to store a string value.
        /// </summary>
        private Collection<FacetStringType> stringField;

        /// <summary>
        /// Used to store a long string value.
        /// </summary>
        private Collection<FacetStringType> longStringField;

        /// <summary>
        /// Used to store a number value.
        /// </summary>
        private Collection<FacetNumberType> numberField;

        /// <summary>
        /// Used to store a Date Time value.
        /// </summary>
        private Collection<FacetDateTimeType> dateTimeField;

        /// <summary>
        /// Used to store a link.
        /// </summary>
        private Collection<FacetLinkType> linkField;

        /// <summary>
        /// Initializes a new instance of the <see cref="Facet"/> class.
        /// </summary>
        public Facet()
        {
            this.stringField = new Collection<FacetStringType>();
            this.longStringField = new Collection<FacetStringType>();
            this.numberField = new Collection<FacetNumberType>();
            this.dateTimeField = new Collection<FacetDateTimeType>();
            this.linkField = new Collection<FacetLinkType>();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Facet"/> class.
        /// </summary>
        /// <param name="facetName">Name of the facet.</param>
        public Facet(string facetName)
            : this()
        {
            this.FacetName = facetName;
        }

        /// <summary>
        /// Gets the text (This is a String in Pivot).
        /// </summary>
        /// <value>The text (This is a String in Pivot).</value>
        [XmlElementAttribute("String")]
        public Collection<FacetStringType> Text
        {
            get
            {
                return this.stringField;
            }
        }

        /// <summary>
        /// Gets the long string.
        /// </summary>
        /// <value>The long string.</value>
        [XmlElementAttribute("LongString")]
        public Collection<FacetStringType> LongString
        {
            get
            {
                return this.longStringField;
            }
        }

        /// <summary>
        /// Gets the number.
        /// </summary>
        /// <value>The number.</value>
        [XmlElementAttribute("Number")]
        public Collection<FacetNumberType> Number
        {
            get
            {
                return this.numberField;
            }
        }

        /// <summary>
        /// Gets the date time.
        /// </summary>
        /// <value>The date time.</value>
        [XmlElementAttribute("DateTime")]
        public Collection<FacetDateTimeType> DateTime
        {
            get
            {
                return this.dateTimeField;
            }
        }

        /// <summary>
        /// Gets the hyperlink.
        /// </summary>
        /// <value>The hyperlink.</value>
        [XmlElementAttribute("Link")]
        public Collection<FacetLinkType> Link
        {
            get
            {
                return this.linkField;
            }
        }

        /// <summary>
        /// Gets or sets the name of the Facet.
        /// </summary>
        /// <value>The name of the Facet.</value>
        [XmlAttribute(AttributeName = "Name")]
        public string FacetName { get; set; }


        public override string ToString()
        {
            return this.FacetName;
        }
    }
}
